import javax.activation.*;

import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
//import javax.mail.com.sun.mail.util;

import com.sun.mail.util.MailSSLSocketFactory;

public class SendEmail {
	//������ϸ����
	static String noteTitle, noteContent, mail, id;
	Timestamp t;
	
	public SendEmail(Timestamp time) {
		String[] detail;
		try {
			//��ȡ��ϸ��Ϣ
			DatabaseCtrl.init();
			detail = DatabaseCtrl.getDetail(time);
			noteTitle = detail[0];
			noteContent = detail[1];
			mail = detail[2];
			id = detail[3];
			//DatabaseCtrl.close();
						
			System.out.println("�ʼ���Ϣ��"+ detail);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	
    public static void main(String[] args) throws Exception {

        Properties prop = new Properties();
        prop.setProperty("mail.host", "smtp.qq.com"); // ����QQ�ʼ�������
        prop.setProperty("mail.transport.protocol", "smtp"); // �ʼ�����Э��
        prop.setProperty("mail.smtp.auth", "true"); // ��Ҫ��֤�û�������

        // ����QQ���䣬��Ҫ����SSL���ܣ��������´��뼴��
        MailSSLSocketFactory sf = new MailSSLSocketFactory();
        sf.setTrustAllHosts(true);
        prop.put("mail.smtp.ssl.enable", "true");
        prop.put("mail.smtp.ssl.socketFactory", sf);

        //ʹ��JavaMail�����ʼ���5������

        //������������Ӧ�ó�������Ļ�����Ϣ�� Session ����

        Session session = Session.getDefaultInstance(prop, new Authenticator() {
            public PasswordAuthentication getPasswordAuthentication() {
                //�������ʼ��û�������Ȩ��
                return new PasswordAuthentication("1450316540@qq.com", "ajczvoccunxkgaeg");
            }
        });


        //����Session��debugģʽ�������Ϳ��Բ鿴��������Email������״̬
        session.setDebug(true);

        //2��ͨ��session�õ�transport����
        Transport ts = session.getTransport();

        //3��ʹ��������û�������Ȩ�������ʼ�������
        ts.connect("smtp.qq.com", "1450316540@qq.com", "ajczvoccunxkgaeg");

        //4�������ʼ�

        //�����ʼ�����
        MimeMessage message = new MimeMessage(session);

        //ָ���ʼ��ķ�����
        message.setFrom(new InternetAddress("1450316540@qq.com"));

        //ָ���ʼ����ռ��ˣ����ڷ����˺��ռ�����һ���ģ��Ǿ����Լ����Լ���
        message.setRecipient(Message.RecipientType.TO, new InternetAddress(mail));

        //�ʼ��ı���
        message.setSubject(noteTitle);

        //�ʼ����ı�����
        message.setContent(noteContent, "text/html;charset=UTF-8");

        //5�������ʼ�
        ts.sendMessage(message, message.getAllRecipients());

        ts.close();
        
        System.out.println("�ʼ��ѷ��ͣ�");
    }

}
